
outlw_MR_openKeybindings =
{
	createDialog "MagRepack_Dialog_Keybindings";
	outlw_MR_keybindingMenuActive = true;
	
	outlw_MR_pressedKeys = [];
	
	outlw_KB_current =+ outlw_MR_keyList;
	outlw_KB_recent = [outlw_KB_current];
	outlw_KB_canAdd = true;
	
	call outlw_KB_updateKeyText;
	
	((uiNamespace getVariable "outlw_MR_Dialog_Keybindings") displayCtrl 2401) ctrlEnable false;
	((uiNamespace getVariable "outlw_MR_Dialog_Keybindings") displayCtrl 2404) ctrlEnable false;
};

outlw_MR_applyKeybinding =
{
	outlw_MR_keyList =+ (_this select 0);
	profileNamespace setVariable ["outlw_MR_keyList_profile", outlw_MR_keyList];
	closeDialog 0;
};

outlw_KB_keyDown =
{
	if ((_this select 1) != 1) then
	{
		call outlw_MR_keyDown;
		
		if (outlw_KB_canAdd) then
		{
			outlw_KB_current =+ outlw_MR_pressedKeys;
			call outlw_KB_updateKeyText;
		};
		
		true;
	};
};

outlw_KB_keyUp =
{
	call outlw_MR_keyUp;
	
	if (count outlw_MR_pressedKeys == 0) then
	{
		outlw_KB_canAdd = true;
		outlw_KB_recent set [count outlw_KB_recent, outlw_KB_current];
		
		call outlw_KB_enableButtons;
	}
	else
	{
		outlw_KB_canAdd = false;
	};
	
	true;
};

outlw_KB_undoKeybinding =
{
	outlw_KB_recent set [((count outlw_KB_recent) - 1), 42];
	outlw_KB_recent = outlw_KB_recent - [42];
	
	outlw_KB_current =+ (outlw_KB_recent select ((count outlw_KB_recent) - 1));
	call outlw_KB_updateKeyText;
	
	call outlw_KB_enableButtons;
};

outlw_KB_defaultKeybinding =
{
	outlw_KB_current = [29,19];
	outlw_KB_recent set [count outlw_KB_recent, outlw_KB_current];
	call outlw_KB_updateKeyText;
	
	call outlw_KB_enableButtons;
};

outlw_KB_enableButtons =
{
	if !([outlw_MR_keyList, (outlw_KB_recent select ((count outlw_KB_recent) - 1))] call BIS_fnc_arrayCompare) then
	{
		((uiNamespace getVariable "outlw_MR_Dialog_Keybindings") displayCtrl 2401) ctrlEnable true;
	}
	else
	{
		((uiNamespace getVariable "outlw_MR_Dialog_Keybindings") displayCtrl 2401) ctrlEnable false;
	};
	
	if (count outlw_KB_recent > 1) then
	{
		((uiNamespace getVariable "outlw_MR_Dialog_Keybindings") displayCtrl 2404) ctrlEnable true;
	}
	else
	{
		((uiNamespace getVariable "outlw_MR_Dialog_Keybindings") displayCtrl 2404) ctrlEnable false;
	};
};

outlw_KB_updateKeyText =
{
	((uiNamespace getVariable "outlw_MR_Dialog_Keybindings") displayCtrl 1001) ctrlSetText ([([outlw_KB_current] call outlw_MR_keyCodeToString),17] call outlw_MR_shortString);
	((uiNamespace getVariable "outlw_MR_Dialog_Keybindings") displayCtrl 1003) ctrlSetToolTip ([outlw_KB_current] call outlw_MR_keyCodeToString);
};



